$(window).load(function(){
			 
				//global vars
				var form = $("#frmVehicle");
				var name = $("#txtVin");
				var nameInfo = $("#nameInfo");
				//On blur
				name.blur(validateName);
				
				//On key press
				name.keyup(validateName);
				
				
				//validation functions
				
				function validateName(){
					//if it's NOT valid
					if(name.val().length < 1){
						name.removeClass("tb7");
						name.addClass("errortxt");
						nameInfo.text("Vin Code is Required!");
						nameInfo.css('display', 'block');
						nameInfo.addClass("errorlbl");
						return false;
					}
					//if it's valid
					else{
						name.removeClass("errortxt");
						name.addClass("tb7");
						nameInfo.css('display', 'none');
						nameInfo.text("Vin Code is Required!");
						nameInfo.removeClass("errorlbl");
						return true;
					}
				}
			 
				$("#tabs").tabs({

					select: function(event, ui) {
						var valid = true;
						var current = $(this).tabs("option", "selected");
						var panelId = $("#tabs ul a").eq(current).attr("href");

						if(ui.index > current)
						{
							$(panelId).find("input").each(function() {
								//console.log(valid);

								if (validateName() && valid) {
									$("#hidVin").val($("#txtVin").val());
									valid = true;
								}
								else
								{
									valid = false;
								}
							});

						}

						return valid;
					}   

				});
				
				$("#btnBasicData").click(function() {
				if(validateName() )
				{
					var vehicleStatus = $("input[@name='VehicleStatus']:checked").val();
					var txtyear  = $("#txtyear").val();
					var txtmake = $("#txtmake").val();
					var txtmodel = $("#txtmodel").val();
					var txtVin = $("#txtVin").val();
					var txtStockNumber = $("#txtStockNumber").val();
					var txtstyle = $("#txtstyle").val();
					var txtExColor =  $("#txtExColor").val();
					var txtdoors = $("#txtdoors").val();
					var txtbPassengers =  $("#txtbPassengers").val();
					var txtbKM =  $("#txtbKM").val();
					var txtbFuel =  $("#txtbFuel").val();
					var txtbEngine =  $("#txtbEngine").val();
					var txtbInterior =  $("#txtbInterior").val();
					
					//alert(txtbInterior);

					 $.post("common-save-functions.php",{vehicleStatus:vehicleStatus,txtyear:txtyear,txtmake:txtmake,txtmodel:txtmodel,txtVin:txtVin,txtStockNumber:txtStockNumber,txtstyle:txtstyle,txtExColor:txtExColor,txtdoors:txtdoors,txtbPassengers:txtbPassengers,txtbKM:txtbKM,txtbFuel:txtbFuel,txtbEngine:txtbEngine,txtbInterior:txtbInterior,action:"basicdata"},function(data)
					 {   	
						 $("#tabs").tabs("select", 1);
						// alert(txtVin+"===="+$("#hidVin").val());
					 },"text");
					
					return true;					
				}
				else
				{
					return false;
				}
					
				});				
				$("#btnVehicleUpload").click(function() {
					
					$("#tabs").tabs("select", 2);
				});
				$("#btnVehicleLocation").click(function() {
					
					var txtVin = $("#txtVin").val();
					var rdbtnLocation = $("#rdbtnLocation").val();
					//alert(txtVin +"-------------------->>"+rdbtnLocation);
					$.post("common-save-functions.php",{txtVin:txtVin,rdbtnLocation:rdbtnLocation,action:"locationdata"},function(data)
					{
						$("#tabs").tabs("select", 3);
					},"text");
				});
				$("#btnPrice").click(function() {
					var txtVin = $("#txtVin").val();
					var txtoriginalprice = $("#txtoriginalprice").val();
					var txtofferedprice = $("#txtofferedprice").val();
					var txtfprice = $("#txtfprice").val();
					var txtifeatured = $("#txtifeatured").val();
					var txtdiscount = $("#txtdiscount").val();
					
					$.post("common-save-functions.php",{txtVin:txtVin,txtoriginalprice:txtoriginalprice,txtofferedprice:txtofferedprice,txtfprice:txtfprice,txtifeatured:txtifeatured,txtdiscount:txtdiscount,action:"pricedata"},function(data)
							 {
						$("#tabs").tabs("select", 4);
							 },"text")					
				});	
				/*$("#btnWM").click(function() {
					var txtVin = $("#txtVin").val();
					var txtgrossweightrange = $("#txtgrossweightrange").val();
					var txtmpayload = $("#txtmpayload").val();
					var txtmtcapacity = $("#txtmtcapacity").val();
					var txtbtcapacity = $("#txtbtcapacity").val();
						
					$.post("common-save-functions.php",{txtVin:txtVin,txtgrossweightrange:txtgrossweightrange,txtmpayload:txtmpayload,txtmtcapacity:txtmtcapacity,txtbtcapacity:txtbtcapacity,action:"wmdata"},function(data)
							 {
						$("#tabs").tabs("select", 5);
							 },"text")
					
				});	*/		
				$("#btnFeatures").click(function() {
					var txtVin = $("#txtVin").val();
					var txtfaconditioning = $("#txtfaconditioning").val();
					var txtfaczones = $("#txtfaczones").val();
					var txtraconditioning = $("#txtraconditioning").val();
					var txtairbags = $("#txtairbags").val();
					var txtcdchanger = $("#txtcdchanger").val();
					var txthjaks = $("#txthjaks").val();
					var txtmp3player = $("#txtmp3player").val();
					var txtradio = $("#txtradio").val();
					var txtrdsystem = $("#txtrdsystem").val();
					var txtrearaudio = $("#txtrearaudio").val();
					var txtssvcontrol = $("#txtssvcontrol").val();
					var txtsubwoofer = $("#txtsubwoofer").val();
					var txtOptionsFeatures = $("#txtOptionsFeatures").val();
					$.post("common-save-functions.php",{txtOptionsFeatures:txtOptionsFeatures,txtVin:txtVin,txtfaconditioning:txtfaconditioning,txtfaczones:txtfaczones,txtraconditioning:txtraconditioning,txtairbags:txtairbags,txtcdchanger:txtcdchanger,txthjaks:txthjaks,txtmp3player:txtmp3player,txtradio:txtradio,txtrdsystem:txtrdsystem,txtrearaudio:txtrearaudio,txtssvcontrol:txtssvcontrol,txtsubwoofer:txtsubwoofer,action:"featuredata"},function(data)
							 {
						$("#tabs").tabs("select", 5);
						
							 },"text")
					
				});
				/*
				$("#btnBrakes").click(function() {
					$("#tabs").tabs("select", 7);
				});
				$("#btnChildSafety").click(function() {
					$("#tabs").tabs("select", 8);
				});	
				$("#btnCM").click(function() {
					$("#tabs").tabs("select", 9);
				});	
				$("#btnDoors").click(function() {
					$("#tabs").tabs("select", 10);
				});		
				$("#btnDriverSeat").click(function() {
					$("#tabs").tabs("select", 11);
				});	
				$("#btnExtendedFeatures").click(function() {
					$("#tabs").tabs("select", 12);
				});		
					*/
				$("#btnExteriorFeatures").click(function() {
					$("#tabs").tabs("select", 6);
				});	
				/*
				$("#btnSecurity").click(function() {
					$("#tabs").tabs("select", 14);
				});	
				$("#btnWarranty").click(function() {
					$("#tabs").tabs("select", 15);
				});	*/
				$("#btnAdditionalInfo").click(function() {
					$("#tabs").tabs("select", 7);
				});	
				$("#btnYoutubeVideo").click(function() {
					alert("Saved Successfully!");
				});	
				$(".nexttab").click(function() {
					$("#tabs").tabs("select", this.hash);
				});
				
				
			});

